<?php
$obj=new mysql($config);

if(!empty($_POST)){
  $_POST['createtime']=time();
  $_POST['user_id']=$_SESSION['user']['id'];
  $row=$obj->insert($_POST,'message');
  if($row>0){
   
    // $filename="./cach/{$_POST["news_id"]}.html";
    // if(file_exists($filename)){
    //      unlink($filename);
    //      $file="http://localhost/cms/index.php?c=list&a=news-detail&id=".$_POST["news_id"];
    //      $content=file_get_contents($file);
    //      str_replace('/cach/index.php','/index.php',$content);
    // }
	echo "<script>alert('发表成功');window.reload();</script>";    
    
  }
  else{
  	echo "<script>alert('发表失败');window.reload();</script>";
  	
  }
}






$id=!empty($_GET['id'])?$_GET['id']:'';
$sql="select * from `news` where `id`=$id";
$date=$obj->getOne($sql);


$sql1="select pid from `cate` where `cate_type`=1 and `id`=$date[cid]";
$dates=$obj->getOne($sql1);
$sql2="select id from `cate` where `cate_type`=1 and `pid`=$dates[pid]";
$date2=$obj->getCondition($sql2);
$ids=array();
foreach ($date2 as $k => $v) {
	$ids[]=$v['id'];
}
$ids=implode(',',$ids);
$sql3="select * from `cate` where `cate_type`=1 and `id` in ($ids)";

$date3=$obj->getCondition($sql3);




// 搜索当前新闻列表对应id的留言
$sql="select `message`.*,`user`.`name` from `message` inner join `user` on `user`.`id`=`message`.`user_id` where `message`.`news_id`=$id";
$rep=$obj->getCondition($sql);






require_once VIEW_PATH.'home/layout.html';
